/**
 * Created by liuqingxia on 2016/3/3.
 */
$(document).ready(function () {

    var url = getRoot() + "/admin/project/insert";

    $(document).on("click", "#commitBtn", function () {

        var params = {};
        params['projectName'] = $("#projectName").val();
        params['projectEmail'] = $("#projectEmail").val();
        params['projectPhone']= $("#projectPhone").val();
        var projectUsers = [];

        $.each($(".projectUsers"), function () {
            if (this.checked) {
                projectUsers.push(this.value);
            }
        });
        params['projectUsers'] = projectUsers.join(",");
        $.postHttp(params,url,function(json){
            if (json && json.success) {
                swal("成功",json['message'],"success");
            } else {
                if (json) {
                    swal("失败",json['message'], 'error');
                }
            }
        })
    });

    $(document).on("click", "#validateProjectName-btn", function () {
        var params = {};
        params['projectName'] = $("#projectName").val();
        if(isNull(params['projectName'])){
            swal("警告","请输入项目组名","warning");
            return;
        }
        var url = getRoot() + "/project/findByName"
        $.postHttp(params,url,function(json){
            if (json && !json.success) {
                swal("成功","该项目名可用","success");
            } else {
                if (json) {
                    swal("失败","该项目名已经存在", 'error');
                }
            }
        })
    });
});
